/*
 * Copyright (C) 2016 The Android Open Source Project
 *  Created by  Ant  2016/9/30  11:41
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.ant.birds.beans;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;

/**
 * Created by baichuan on 2016/9/30.
 */
public class BirdBean {

    private int x;
    private int y;
    private int width;
    private int height;
    private Rect rect;

    private int minLow = 0;
    private int slowSpeed = 5;

    private Resources resources;
    private Bitmap birdBitmap;
    private int birdId = 0;

    public BirdBean(Resources resources, int birdResouceId) {
        this.resources = resources;
        this.birdId = birdResouceId;

        initeSele();
    }


    private void initeSele() {
        x = 0;
        y = 0;
        birdBitmap = BitmapFactory.decodeResource(resources, birdId);

        rect = new Rect();
    }

    public void drawSelf(Canvas canvas) {
        if (canvas != null) {
            rect.set(x, y, x + birdBitmap.getWidth(), y + birdBitmap.getHeight());
            canvas.drawBitmap(birdBitmap, x, y, null);
            changeX();
        }
    }


    /**
     * change birde x of scream
     */
    private void changeX() {
        if (y <= minLow)
            y = y + slowSpeed;
    }


    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public Rect getRect() {
        return rect;
    }

    public void setRect(Rect rect) {
        this.rect = rect;
    }

    public int getMinLow() {
        return minLow;
    }

    public void setMinLow(int minLow) {
        this.minLow = minLow;
    }

    public int getSlowSpeed() {
        return slowSpeed;
    }

    public void setSlowSpeed(int slowSpeed) {
        this.slowSpeed = slowSpeed;
    }


    public void setBiredUp(int deltY) {
        y = y - deltY;
        if (y <= 0)
            y = 0;
    }
}
